<?php
require('check_init.php'); 
?>
<h1><?php echo _XG_NETPBM27;?></h1>
<?php echo _XG_NETPBM28;?> <?php echo _XG_NETPBM03;?> 
<?php echo _XG_NETPBM29;?>
<p><ol>
<li><?php echo _XG_NETPBM05;?>
<p><?php echo _XG_NETPBM06;?><br>
<b><?php passthru("uname -a"); ?></b>
<p><?php echo _XG_NETPBM07;?><br>
<b><?php echo php_uname() ?></b>
<p>
<?php echo _XG_NETPBM08;?>
<p>
<?php echo _XG_NETPBM09;?> <?php echo _XG_NETPBM10;?> <?php echo _XG_NETPBM11;?> 
<a href="http://www.netcraft.com/whats?host=<?php echo $_SERVER['HTTP_HOST']?>"><?php echo _XG_NETPBM13;?></a><?php echo _XG_NETPBM12;?><p>
<p><li><?php echo _XG_NETPBM30;?><p><ul><b><?php echo $gallery->app->ImPath ?></b></ul>
<p><?php echo _XG_NETPBM31;?><p><?php $debugfile = tempnam($gallery->app->tmpDir, "gallerydbg");?>
<?php
if (!inOpenBasedir($gallery->app->imDir)) {
?>
 <?php echo _XG_NETPBM16;?> <?php echo _XG_NETPBM32;?><?php echo $gallery->app->imDir ?><?php echo _XG_NETPBM33;?><ul>
 <?php echo join('<br>', explode(':', ini_get('open_basedir'))) ?>
 </ul>
 <?php echo _XG_NETPBM34;?><br><br>
<?php
}
?>
<li><?php echo _XG_NETPBM36;?>
<?php
if ($show_details) {
	print "<a href=\"index.php?op=check_imagemagick&amp;show_details=0\">"._XG_NETPBM47."</a> "._XG_NETPBM48."</a>";
} else {
	print _XG_NETPBM49." <a href=\"index.php?op=check_imagemagick&amp;show_details=1\">"._XG_NETPBM47."</a> "._XG_NETPBM50."</a>";
}
?>

<pre>
<?php
$binaries = array(
		"identify",
		"convert",
		"composite"
	    );

foreach ($binaries as $bin) {
	checkImageMagick($bin, $gallery, $show_details, $debugfile);
}

if (fs_file_exists($debugfile)) {
    fs_unlink($debugfile);
}

function checkImageMagick($cmd, $gallery, $show_details, $debugfile) {

	$cmd = fs_executable($gallery->app->ImPath . "/$cmd");
	print _XG_NETPBM19. fs_import_filename($cmd). "\n";

	$ok = 1;

	if ($ok) {
		if (inOpenBasedir($gallery->app->pnmDir)) {
			if (!fs_file_exists($cmd)) {
				$error = sprintf(_XG_NETPBM20, $cmd);
				$ok = 0;
			}
		}
	}

	$cmd .= " -help";
	
	fs_exec($cmd, $results, $status, $debugfile);
    
	if ($ok) {
		if ($status != $gallery->app->expectedExecStatus) {
			$error = _XG_NETPBM24 .
				$gallery->app->expectedExecStatus .
				_XG_NETPBM25." $status";
			$ok = 0;
		}
	}

	/*
	 * Windows does not appear to allow us to redirect STDERR output, which
	 * means that we can't detect the version number.
	 */
	if ($ok) {
	    if (substr(PHP_OS, 0, 3) == 'WIN') {
			$version = "<i>"._XG_NETPBM23."</i>";
	    }
		else if (eregi("version: (.*) http(.*)$", $results[0], $regs)) {
			$version = $regs[1];
		} else {
			$error = $results[0];
			$ok = 0;
		}
	}

	if ($ok) {
		print "<font color=green>". _XG_NETPBM22 ." $version</font>";
	} else {
		print "<font color=red>". _XG_NETPBM21 ." ($error) </font>";
	}
	print "\n\n";
}
    
function inOpenBasedir($dir) {
    $openBasedir = ini_get('open_basedir');
    if (empty($openBasedir)) {
	return true;
    }

    return in_array($dir, explode(':', $openBasedir));
}
    
?>
</pre>

<p>
<?php echo _XG_NETPBM37;?> <b><?php echo $debugfile ?></b><?php echo _XG_NETPBM38;?> <?php echo _XG_NETPBM39;?> <a
href="http://www.php.net/manual/en/configuration.php#ini.open-basedir"><?php echo _XG_NETPBM40;?></a> <?php echo _XG_NETPBM41;?> 
<?php echo _XG_NETPBM42;?> <a href="http://gallery.sourceforge.net/help.php"><?php echo _XG_NETPBM43;?></a>
<p>
<?php echo _XG_NETPBM44;?> <a href="http://gallery.sourceforge.net/faq.php"><?php echo _XG_NETPBM45;?></a> 4.4 <?php echo _XG_NETPBM46;?></ol>